package com.yuyou.hxyy.gateway.security.handler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import com.yuyou.hxyy.gateway.security.UserDetailsImpl;
import com.yuyou.hxyy.service.api.bean.ReturnResult;

@Component
public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
    	UserDetailsImpl custUserDetails=(UserDetailsImpl)authentication.getPrincipal();  
		ReturnResult ret=ReturnResult.returnRes(true, null, custUserDetails.getResp());		
		httpServletResponse.setHeader("Content-type", "text/html;charset=UTF-8");
		httpServletResponse.setCharacterEncoding("UTF-8");
		String data = ret.toJsonString();
		PrintWriter pw = httpServletResponse.getWriter();
		pw.write(data);
		
    }
}